import axios from 'axios'
import { BASE_URL } from '../config/env'

export interface UserCard {
  name: string
  reason: string
  cards: number[]
}

export interface Server {
  id?: number
  ip: string
  user_name: string
  password: string
  dev_type: string
  dev_name: string
  status?: string
  server_room: string
  server_rack: string
  pos_u: string
  location: string
  asset_number: string
  serial_number: string
  rfid: string
  user_cards: UserCard[]
  optical_module_serials?: string[]
  remark: string
  update_time?: string
}

export const serverApi = {
  // 获取服务器列表
  getServers(skip: number = 0, limit: number = 100) {
    return axios.get(`${BASE_URL}/ascend-servers/?skip=${skip}&limit=${limit}`)
  },

  // 创建服务器
  createServer(server: Omit<Server, 'id' | 'status' | 'update_time'>) {
    return axios.post(`${BASE_URL}/ascend-servers/`, server)
  },

  // 更新服务器
  updateServer(id: number, server: Partial<Server>) {
    return axios.put(`${BASE_URL}/ascend-servers/${id}`, server)
  },

  // 删除服务器
  deleteServer(id: number) {
    return axios.delete(`${BASE_URL}/ascend-servers/${id}`)
  }
} 